package Q290

import java.util.Arrays




/**
 * 单词规律
 * @author 23737
 * @date 2022.5.8
 */
class Main {

}

fun main(){
    val s = "abba"
    val t = "dog cat cat dog"
    println(Solution().wordPattern(s, t))
}

/**
 * 使用两个stringBuilder来找规律并且判断比较
 */
class Solution {
    fun wordPattern(pattern: String, s: String): Boolean {
        val s1 = StringBuilder()
        val s2 = StringBuilder()
        for (element in pattern) {
            s1.append(pattern.indexOf(element))
        }
        val arr = s.split(" ".toRegex()).toTypedArray()
        val list = arr.asList()
        println(list.size)
        for (s in list) {
            println(s)
        }
        for (str in arr) {
            s2.append(list.indexOf(str))
        }
        return s1.toString() == s2.toString()
    }
}